import { Injectable } from '@angular/core';
import {HttpClient} from "@angular/common/http";
import {HostService} from "./host.service";
import {Dept} from "../model/Dept";
import {AdminRange} from "../model/AdminRange";
import {RoleGroup} from "../model/RoleGroup";
import {RoleResourseParm} from "../model/RoleResourseParm";
import {RightRoleResourse} from "../model/RightRoleResourse";
import {Member} from "../model/Member";

@Injectable({
  providedIn: 'root'
})
export class ManageService {

  constructor(private http: HttpClient,
              private host:HostService) {
  }

  public HR_MANAGE_HOST = this.host.AuthHOST+"/";

  private getDeptNzTreeURL = this.HR_MANAGE_HOST + "member/getDeptNzTree"

  getDeptNzTree() {
    return this.http.get(this.getDeptNzTreeURL).toPromise();
  }

  private getMemberListByDeptIdURL = this.HR_MANAGE_HOST + "member/getMemberListByDeptId";

  getMemberListByDeptid(deptid: string) {
    let parm = {
      "dept": deptid
    }
    return this.http.post(this.getMemberListByDeptIdURL, parm).toPromise();
  }

  private deleteDeptUrl = this.HR_MANAGE_HOST + "member/deleteDept";

  deleteDept(id: string) {

    let parm = {
      "deptid": id
    }
    return this.http.post(this.deleteDeptUrl, parm).toPromise();

  }

  private saveDeptUrl = this.HR_MANAGE_HOST + "member/saveDept";

  saveDept(dept: Dept) {
    return this.http.post(this.saveDeptUrl, dept).toPromise();
  }

  private getSingleDeptUrl = this.HR_MANAGE_HOST + "member/getSingleDept";

  getSingleDept(id: string) {
    let parm = {
      "deptid": id
    }
    return this.http.post(this.getSingleDeptUrl, parm).toPromise();

  }

  private deleteMemberUrl = this.HR_MANAGE_HOST + "member/deleteMember";

  deleteMember(id: string) {
    let parm = {
      "memberid": id
    }
    return this.http.post(this.deleteMemberUrl, parm).toPromise();
  }

  private getMemberByIdURL = this.HR_MANAGE_HOST + "member/getMemberById";

  getMemberById(id: string) {
    let parm = {
      "memberid": id
    }
    return this.http.post(this.getMemberByIdURL, parm).toPromise();
  }

  private saveMemberUrl = this.HR_MANAGE_HOST + "member/saveMember";

  saveMember(member: Member) {
    return this.http.post(this.saveMemberUrl, member).toPromise();
  }
 private updateMemberUrl = this.HR_MANAGE_HOST + "member/updateMember";

  updateMember(member: Member) {
    return this.http.post(this.updateMemberUrl, member).toPromise();
  }

  private getRoleGroupNzSelListURL = this.HR_MANAGE_HOST + "member/getRoleGroupNzSelList";

  getRoleGroupNzSelList() {
    return this.http.get(this.getRoleGroupNzSelListURL).toPromise();
  }

  private getNzOrganizationTreeURL = this.HR_MANAGE_HOST + "member/getNzOrganizationTree";

  getNzOrganizationTree() {
    return this.http.get(this.getNzOrganizationTreeURL).toPromise();
  }

  private getAdminRangeOrgidByAdminIdURL = this.HR_MANAGE_HOST + "member/getAdminRangeOrgidByAdminId";

  getAdminRangeOrgidByAdminId(adminid: string) {
    let parm = {
      "memberid": adminid
    }
    return this.http.post(this.getAdminRangeOrgidByAdminIdURL, parm).toPromise();
  }

  private saveAdminRangeURL = this.HR_MANAGE_HOST + "member/saveAdminRange";

  saveAdminRange(a: AdminRange) {
    return this.http.post(this.saveAdminRangeURL, a).toPromise();
  }

  private getRoleGroupListUrl = this.HR_MANAGE_HOST + "member/getRoleGroupList";

  getRoleList() {
    return this.http.get(this.getRoleGroupListUrl).toPromise();
  }

  private getRoleGroupByIdURL = this.HR_MANAGE_HOST + "member/getRoleGroupById";

  getRoleGroupById(id: string) {
    let parm = {
      "rolegroupid": id
    }
    return this.http.post(this.getRoleGroupByIdURL, parm).toPromise();
  }

  private saveRoleGroupUrl = this.HR_MANAGE_HOST + "member/saveRoleGroup";

  saveRoleGroup(role: RoleGroup) {
    return this.http.post(this.saveRoleGroupUrl, role).toPromise();
  }

  private deleteRoleGroupURL = this.HR_MANAGE_HOST + "member/deleteRoleGroup";

  deleteRole(id: string) {
    let parm = {
      "rolegroupid": id
    }
    return this.http.post(this.deleteRoleGroupURL, parm).toPromise();
  }

  private getRightNzTreeByTypeURL = this.HR_MANAGE_HOST + "member/getRightNzTreeByType";

  getRightNzTreeByType(type: string) {
    let parm = {
      "type": type
    }
    return this.http.post(this.getRightNzTreeByTypeURL, parm).toPromise()
  }
  private getRightNzTreeByTypeForZyzcURL = this.HR_MANAGE_HOST + "member/getRightNzTreeByTypeForZyzc";

  getRightNzTreeByTypeForZyzc(type: string) {
    let parm = {
      "type": type
    }
    return this.http.post(this.getRightNzTreeByTypeForZyzcURL, parm).toPromise()
  }

  private getResourserTreeByTypeAndRoleURL = this.HR_MANAGE_HOST + "member/getResourserTreeByTypeAndRole";

  getResourserTreeByTypeAndRole(id: string, type: string) {
    let parm = {
      "role": id,
      "type": type
    }
    return this.http.post(this.getResourserTreeByTypeAndRoleURL, parm).toPromise()
  }

  private saveRoleResourceURL = this.HR_MANAGE_HOST + "member/saveRoleResourse";

  saveRoleResource(parm: RoleResourseParm) {

    return this.http.post(this.saveRoleResourceURL, parm).toPromise();
  }

  private getRightresourceByidURL = this.HR_MANAGE_HOST + "member/getRightresourceByid";

  getRightresourceByid(id: string) {
    let parm = {
      "resourceid": id
    }
    return this.http.post(this.getRightresourceByidURL, parm).toPromise()
  }

  private saveRightresourceURL = this.HR_MANAGE_HOST + "member/saveRightresource";

  saveRightresource(parm: RightRoleResourse) {

    return this.http.post(this.saveRightresourceURL, parm).toPromise()
  }

  private deleteRightresourceURL = this.HR_MANAGE_HOST + "member/deleteRightresource";

  deleteRightresource(id: string) {
    let parm = {
      "resourceid": id
    }
    return this.http.post(this.deleteRightresourceURL, parm).toPromise()
  }
}
